package com.ruoyi.web.controller.ex;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.doudou.core.lang.Option;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ex.domain.ExStudyCount;
import com.ruoyi.ex.service.IExStudyCountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ex_study_countController
 *
 * @author zzx
 * @date 2023-07-14
 */
@RestController
@RequestMapping("/ex/ex_study_count")
public class ExStudyCountController extends BaseController {
    @Autowired
    private IExStudyCountService exStudyCountService;

    /**
     * 查询ex_study_count列表
     */
    @PreAuthorize("@ss.hasPermi('ex:ex_study_count:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExStudyCount exStudyCount) {
        startPage();
        List<ExStudyCount> list = exStudyCountService.selectExStudyCountList(exStudyCount);
        return getDataTable(list);
    }

    @GetMapping("/get-study-count-by-stu/{userId}")
    public TableDataInfo getStudyCountByStu(@PathVariable("userId")Long userId) {
        List<ExStudyCount> list = exStudyCountService.getStudyCountByStu(userId);
        return getDataTable(list);
    }

    /**
     * 导出ex_study_count列表
     */
    @PreAuthorize("@ss.hasPermi('ex:ex_study_count:export')")
    @Log(title = "ex_study_count", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExStudyCount exStudyCount) {
        List<ExStudyCount> list = exStudyCountService.selectExStudyCountList(exStudyCount);
        ExcelUtil<ExStudyCount> util = new ExcelUtil<ExStudyCount>(ExStudyCount.class);
        util.exportExcel(response, list, "ex_study_count数据");
    }

    /**
     * 获取ex_study_count详细信息
     */
    @PreAuthorize("@ss.hasPermi('ex:ex_study_count:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(exStudyCountService.selectExStudyCountById(id));
    }

    /**
     * 新增ex_study_count
     */
    @Log(title = "ex_study_count", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExStudyCount exStudyCount) {
        Option<Long> op = Option.of(exStudyCount.getStuId());
        exStudyCount.setStuId(op.get(this::getUserId));
        exStudyCount.setStuId(getUserId());
        return toAjax(exStudyCountService.insertExStudyCount(exStudyCount));
    }

    /**
     * 修改ex_study_count
     */
    @PreAuthorize("@ss.hasPermi('ex:ex_study_count:edit')")
    @Log(title = "ex_study_count", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExStudyCount exStudyCount) {
        return toAjax(exStudyCountService.updateExStudyCount(exStudyCount));
    }

    /**
     * 删除ex_study_count
     */
    @PreAuthorize("@ss.hasPermi('ex:ex_study_count:remove')")
    @Log(title = "ex_study_count", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(exStudyCountService.deleteExStudyCountByIds(ids));
    }
}
